package com.tenglong.teacher.ui.publish;

import android.graphics.Canvas;
import android.graphics.Paint;


import com.cuotibao.zhuoxiao.basics.utils.DensityUtil;
import com.tenglong.teacher.R;

import cn.hzw.doodle.CopyLocation;
import cn.hzw.doodle.DoodleColor;
import cn.hzw.doodle.DoodlePen;
import cn.hzw.doodle.DoodleView;
import cn.hzw.doodle.core.IDoodle;
import cn.hzw.doodle.core.IDoodleItem;
import cn.hzw.doodle.core.IDoodlePen;

/**
 * @author hdx on 2019/5/16.
 */
public enum  ErrorDoodleColor implements IDoodlePen {
    BRUSH, // 画笔
    COPY, // 仿制
    ERASER, // 橡皮擦
    TEXT, // 文本
    BITMAP, // 贴图
    MOSAIC; // 马赛克

    private CopyLocation mCopyLocation;

    @Override
    public void config(IDoodleItem item, Paint paint) {
        if (this == ErrorDoodleColor.COPY || this == ErrorDoodleColor.ERASER) {
            IDoodle doodle = item.getDoodle();
            if ((item.getColor() instanceof DoodleColor)
                    && ((DoodleColor) item.getColor()).getBitmap() == doodle.getBitmap()) {
                // nothing
            } else {
                item.setColor(new DoodleColor(doodle.getBitmap()));
            }
        } else if (this == ErrorDoodleColor.BITMAP ){
            item.setColor(new DoodleColor(R.color.blue));
            paint.setStrokeWidth(DensityUtil.dp2px(20));
        }
    }

    public CopyLocation getCopyLocation() {
        if (this != COPY) {
            return null;
        }
        if (mCopyLocation == null) {
            synchronized (this) {
                if (mCopyLocation == null) {
                    mCopyLocation = new CopyLocation();
                }
            }
        }
        return mCopyLocation;
    }

    @Override
    public IDoodlePen copy() {
        return this;
    }

    @Override
    public void drawHelpers(Canvas canvas, IDoodle doodle) {
        if (this == COPY) {
            if (doodle instanceof DoodleView && !((DoodleView) doodle).isEditMode()) {
                mCopyLocation.drawItSelf(canvas, doodle.getSize());
            }
        }
    }
}
